package hu;

import java.util.*;

public class service {
    static int count1 = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<int[]> list = new ArrayList<>();
        int n = 0;
        while (sc.hasNextLine()){
            String s = sc.nextLine();
            if(s == null || s.length() == 0)
                break;
            String[] str = s.split(" ");
            n = str.length;
            int[] num = new int[n];
            for (int i = 0; i < n; i++) {
                num[i] = Integer.parseInt(str[i]);
            }
            list.add(num);
        }
        int[][] border = new int[n][n];
        for (int i = 0; i < n; i++) {
            border[i] = list.get(i);
        }

        System.out.println(count1);

        /**
         * 并查集
         */
        UF uf = new UF(n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(border[i][j] == 1)
                    uf.uniform(i, j);
            }
        }
        System.out.println(uf.getCount());
    }


    static class UF{
        int count;
        int[] father;
        int[] size;

        public UF(int count) {
            this.count = count;
            father = new int[count];
            size = new int[count];
            for (int i = 0; i < count; i++) {
                father[i] = i;
                size[i] = 1;
            }
        }
        public int getFather(int i){
            if(father[i] == i)
                return i;
            return getFather(father[i]);
        }
        public int getCount(){
            return count;
        }
        public  void uniform(int i, int j){
            int p = getFather(i);
            int q = getFather(j);
            if(p == q)
                return;
            if(size[p] > size[q]){
                father[q] = p;
                size[p] += q;
            }
            else{
                father[p] = q;
                size[q] += p;
            }
            count--;
        }
    }
}
/*
1 0 1
0 1 1
1 1 1
 */